package com.groovy.base

import org.junit.Test

class Example1 {

    // groovy 的循环写法
    static void main(String[] args) {
        def range = 5..10;
        println(range);
        println(range.get(2));
        for (i in 0..<6) {
            println(range.get(i))
        }

        for (int i; i < 6; i++) {
            println(range.get(i))
        }


    }

    @Test
    void test() {
        // Initializing a local variable
        int a = 200

        //Check for the boolean condition
        if (a < 100) {
            //If the condition is true print the following statement
            println("The value is less than 100");
        } else {
            //If the condition is false print the following statement
            println("The value is greater than 100");
        }

    }

    @Test
    public void multipleIfElseTest() {
        // Initializing a local variable
        int a = 12

        //Check for the boolean condition
        if (a > 100) {
            //If the condition is true print the following statement
            println("The value is less than 100");
        } else {
            // Check if the value of a is greater than 5

            if (a > 5) {
                //If the condition is true print the following statement
                println("The value is greater than 5 and greater than 100");
            } else {
                //If the condition is false print the following statement
                println("The value of a is less than 5");
            }

        }

    }


    @Test
    void switchDemo() {
        int a = 2
        switch (a) {
        //There is case statement defined for 4 cases
        // Each case statement section has a break condition to exit the loop
            case 1:
                println("值是 1")
                break
            case 2:
                println("值是 2")
                break
            case 3:
                println("值是 3")
                break
            case 4:
                println("值是 4")
                break
            default:
                println("超出范围的值")
                break


        }
    }

    @Test
    void multipleSwitch() {
        //Initializing 2 variables i and j
        int i = 0;
        int j = 1;

        // First evaluating the value of variable i
        switch(i) {
            case 0:
                // Next evaluating the value of variable j
                switch(j) {
                    case 0:
                        println("i is 0, j is 0");
                        break;
                    case 1:
                        println("i is 0, j is 1");
                        break;

                // The default condition for the inner switch statement
                    default:
                        println("nested default case!!");
                }
                break;

        // The default condition for the outer switch statement
            default:
                println("No matching case found!!");
        }
    }
}
